package org.moriwuzhe.shuttle.spring.example.beanPost;

import org.moriwuzhe.shuttle.common.logger.Logger;
import org.moriwuzhe.shuttle.common.logger.LoggerFactory;
import org.moriwuzhe.shuttle.spring.example.service.ShuttleExampleService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class ShuttleExampleProcessor implements InstantiationAwareBeanPostProcessor {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof ShuttleExampleService) {
            logger.info("加载的beanName:{}, object:{}", beanName, bean);
        }
        if (bean instanceof ShuttleExampleProcessor) {
            logger.info("加载的beanName:{}, object:{}", beanName, bean);
        }
        return bean;
    }
}
